package com.example.hospitalsystem.controller;


import com.example.hospitalsystem.pojo.dto.auth.*;
import com.example.hospitalsystem.pojo.vo.LoginVo;
import com.example.hospitalsystem.result.Result;
import com.example.hospitalsystem.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
@Tag(name="1.认证模块")
public class AuthController {

    @Autowired
    private AuthService authService;

    @Operation(summary="用户注册")
    @PostMapping("/register/pwd")
    public Result<Object> userRegister(@RequestBody RegisterDto registerDto){
         return authService.userRegiister(registerDto);
    }

    @Operation(summary="用户登录")
    @PostMapping("/login/pwd")
    public Result<LoginVo> userLogin(@RequestBody LoginDto loginDto){
        return authService.userLogin(loginDto);
    }

    @Operation(summary = "用户邮箱登录")
    @PostMapping("/login/email")
    public Result<Object> loginByEmail(@RequestBody EmailCaptchaDto emailCaptchaDto){
        return authService.loginByEmail(emailCaptchaDto);
    }

    @Operation(summary = "通过原密码修改密码")
    @PutMapping("/change/pwd")
    public Result<Object> chagePwdByPast(@RequestBody ChangePwd changePwd){
        return authService.changePwdByPast(changePwd);
    }

    @Operation(summary = "绑定邮箱",security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/bindEmail")
    public Result<Object> bindEmail(@RequestBody EmailCaptchaDto emailCaptchaDto){
        return authService.bindEmail(emailCaptchaDto);
    }

    @Operation(summary = "通过邮箱修改密码",security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("/changePwdByEmail")
    public Result<Object> changePwdByEmail(@RequestBody ChangePwdByEmailDto changePwdByEmailDto){
        return authService.changePwdByEmail(changePwdByEmailDto);
    }

    @Operation(summary = "验证旧邮箱")
    @PutMapping("/verifyOldEmail")
    public Result<Object> verifyOldEmail(@RequestBody EmailCaptchaDto emailCaptchaDto){
        return authService.verifyOldEmail(emailCaptchaDto);
    }

    @Operation(summary = "更换邮箱",security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("/changeEmail")
    public Result<Object> changeEmail(@RequestBody ChangeEmailDto changeEmailDto){
        return authService.changeEmail(changeEmailDto);
    }
    @Operation(summary = "解绑邮箱",security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("cancelEmailBind")
    public Result<Object> cancelEmailBind(@RequestBody CancelEmailDto cancelEmailDto){
        return authService.cancelEmailBind(cancelEmailDto);
    }
}
